package com.gmail.blackdog1987.onedollar.dao;

import com.gmail.blackdog1987.onedollar.dao.hibernate.EntityHibernateDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.BaseJdbcDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.JdbcUtil;
import com.gmail.blackdog1987.onedollar.entity.TGoodsShowEntity;
import com.gmail.blackdog1987.onedollar.entity.TLuckybagEntity;
import com.gmail.blackdog1987.onedollar.entity.TUserEntity;
import com.gmail.blackdog1987.onedollar.entity.base.Page;
import com.gmail.blackdog1987.onedollar.vo.GoodsOneDollarVO;
import com.gmail.blackdog1987.onedollar.vo.GoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Repository("luckyBagDao")
public class LuckyBagDao extends EntityHibernateDao<TLuckybagEntity>{
    @Autowired
    private BaseJdbcDao baseJdbcDao;

    public List<TLuckybagEntity> queryNotReceiveBeforeTime(Date time){
        return JdbcUtil.queryForList(baseJdbcDao, TLuckybagEntity.class, "select * from t_luckybag where sendtime <= ? and id in (select luckybag_id from t_luckybag_consume where `status`=0)", new Object[]{time});
    }

    public List<TUserEntity> querySenderNotReceiveBeforeTime(Date time){
        return JdbcUtil.queryForList(baseJdbcDao, TUserEntity.class, "select * from t_user where user_id in (select sender from t_luckybag where sendtime <= ? and availablecount>0)", new Object[]{time});
    }
}
